package reflect;

import CollectionTask.ArrayList;

import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo1 {
    public static void main(String[] args) throws ClassNotFoundException {
      /*  //获取类对象
        Class cla1=String.class;
        Class cla2= ArrayList.class;
        Class cla3=int.class;

        //通过指定类的完全限定名获取一个类的对象
        Class cla4=Class.forName("java.lang.String");
        Class cla5=Class.forName("java.util.ArrayList");
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入一个类名");
        String name=scan.next();
        Class cla6=Class.forName(name);
        */

        Scanner scan=new Scanner(System.in);
        System.out.println("请输入一个类名");
        String name=scan.next();
        Class cls=Class.forName(name);

        System.out.println("获取类的完全限定名:"+cls.getName());
        System.out.println("获取类名:"+cls.getSimpleName());

        Package pack=cls.getPackage();
        System.out.println("获取包名:"+pack.getName());

        Method[]methods=cls.getMethods();
        System.out.println("一共"+methods.length+"个方法");
        for (Method method:methods){
            System.out.println(method.getName());
        }
    }
}
